<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <script>
        $(function () {


           $.ajaxSettings.traditional=true;

           $('#checkAll').click(function () {
               $('table input').prop('checked',this.checked);
           });
           $('.ck').click(function () {
               if ($('.ck:checked').size() == $('.ck').size()) {
                   $('#checkAll').prop('checked',true);
               } else {
                   $('#checkAll').prop('checked',false);
               }
           });

           //批量删除
            $('.batchDelete').click(function () {
                if ($('.ck:checked').size()==0){
                    $.messager.alert("xx","至少选中一个")
                    return;
                }
                $.messager.confirm("温馨提示","确定删除吗",function () {
                    //获取选中元素的id值
                    var ids = $.map($('.ck:checked'),function (ele) {
                        return $(ele).data("eid");
                    });

                    //发送ajax请求访问批量删除的资源
                    $.post("/employee/batchDelete.do",{"ids":ids},function (data) {
                        location.href="/employee/list.do";
                    });
                });
            });
            
            // 导入员工
            $('.importBtn').click(function () {
                $('#importModal').modal('show');
            });
            // 导入的保存操作
            $('.importSubmit').click(function () {
                $('#importForm').submit();
            });
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">员工管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/employee/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}" placeholder="请输入姓名/邮箱">
                </div>
                <div class="form-group">
                    <label for="dept">部门:</label>
                    <select class="form-control" id="dept" name="deptId">
                        <option value="-1">全部</option>
                        <#list depts as d>
                            <option value="${d.id}">${d.name}</option>
                        </#list>
                    </select>
                    <script>
                        $("#dept option[value='${qo.deptId}']").prop("selected", true);
                    </script>
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <@shiro.hasPermission name="employee:saveOrUpdate">
                    <a href="/employee/input.do" class="btn btn-success">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </@shiro.hasPermission>
                <a href="javascript:" class="btn btn-danger batchDelete">
                    <span class="glyphicon glyphicon-trash"></span> 批量删除
                </a>
                <a href="javascript:window.open('/employee/export.do');" class="btn btn-primary">
                    <span class="glyphicon glyphicon-export"></span> 导出员工
                </a>
                <a href="javascript:" class="btn btn-primary importBtn">
                    <span class="glyphicon glyphicon-import"></span> 导入员工
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th><input type="checkbox" id="checkAll"/></th>
                    <th>编号</th>
                    <th>名称</th>
                    <th>email</th>
                    <th>年龄</th>
                    <th>部门</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td><input type="checkbox" class="ck" data-eid="${entity.id}"/></td>
                        <td>${entity_index+1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.email}</td>
                        <td>${entity.age}</td>
                        <td>${(entity.dept.name)!}</td>
                        <td>
                            <@shiro.hasPermission name="employee:input">
                                <a class="btn btn-info btn-xs" href="/employee/input.do?id=${entity.id}">
                                    <span class="glyphicon glyphicon-pencil"></span>编辑
                                </a>
                            </@shiro.hasPermission>
                                <@shiro.hasPermission name="employee:delete">
                                <a href="javascript:" data-url="/employee/delete.do?id=${entity.id}"
                                   class="btn btn-danger btn-xs deleteBtn">
                                    <span class="glyphicon glyphicon-trash"></span>删除
                                </a>
                            </@shiro.hasPermission>
                        </td>
                    </tr>
                </#list>
            </table>
            <div style="text-align: center;">
                <#include "../common/page.ftl">
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">导入员工</h4>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form id="importForm" class="form-horizontal" action="/employee/importEmployee.do"
                      enctype="multipart/form-data" method="post">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label for="name" class="col-lg-4 control-label">上传文件：</label>
                        <div class="col-lg-6">
                            <input type="file" name="xls" accept="application/vnd.ms-excel" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-lg-4 control-label">参考模板：</label>
                        <div class="col-lg-6">
                            <input type="button" class="form-control btn btn-primary" value="下载模板"
                                   onclick="window.open('/template/employee.xls');"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary importSubmit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>